package com.ribbit.web1.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name="auth_user",
  uniqueConstraints = {@UniqueConstraint(columnNames={"username"})}
)
public class User implements Serializable {
    @Id
    @GeneratedValue
    @Column(name = "id")
    private Long id = null;

    @Version
    private int version = 0;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="date_joined", nullable = false, updatable = false)
    private Date joined = new Date();

    @OneToMany(mappedBy="user")
    @Cascade({CascadeType.DELETE})
    private Set<Ribbit> ribbits = new HashSet<Ribbit>();

    @Column(name="username", length=30, nullable=false)
    private String username;

    @Column(name="password", length=128, nullable=false)
    private String password;

    public Long getId() {
        return id;
    }

    public int getVersion() { 
        return version; 
    }

    public Set<Ribbit> getRibbits() {
        return ribbits;
    }

    public void setRibbits(Set<Ribbit> ribbits) {
        this.ribbits = ribbits;
    }

    public Date getJoined() {
        return joined;
    }

    public void setJoined(Date joined) {
        this.joined = joined;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User() {}

    public User(String u, String p) {
       this.username = u;
       this.password = p;
    }
}